package com.huxin.servelt;

import com.alibaba.fastjson.JSON;
import com.huxin.pojo.BookTypeInfo;
import com.huxin.pojo.PageBean;
import com.huxin.service.Userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectbooktype")
public class SLAbookTypeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求方法
        request.setCharacterEncoding("utf-8");
        //处理响应乱码
        response.setContentType("text/json;charset=utf-8");

        int page=1;//开始页
        int size=10;//每页显示十条数据
        if(null!=(request.getParameter("page"))){
            page= Integer.parseInt(request.getParameter("page"));
        }
        if(null!=(request.getParameter("size"))){
            size=Integer.parseInt(request.getParameter("size"));
        }

        Userservice service = new Userservice();
        PageBean<BookTypeInfo> bean =service.selectalltype(page,size);
        String str= JSON.toJSONString(bean);
        response.getWriter().write(str);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
